﻿using System;
using RomanNumeralKata.Core;

namespace RomanNumeralKata
{
    /// <summary>
    ///     Main application class to drive input etc
    /// </summary>
    public class RomanNumeralApplication
    {
        private IRomanNumeralConverter _converter;

        /// <summary>
        ///     immplementation dependent on registrations
        /// </summary>
        /// <param name="converter"></param>
        public RomanNumeralApplication(IRomanNumeralConverter converter)
        {
            _converter = converter;
        }

        public void Run()
        {
            string input = String.Empty;
            string romanNummeral;

            while (input != "quit")
            {
                
                Console.Write("Enter an arabic number (type quit to exit): ");
                input = Console.ReadLine();


                try
                {
                    int arabicNumber;
                    bool parseSucceeded = int.TryParse(input, out arabicNumber);
                    if (!parseSucceeded)
                    {
                        Console.WriteLine(input + " was not a vlid arabic number.");
                        continue;
                       
                    }

                    romanNummeral = _converter.ConvertArabicToRomanNumeral(arabicNumber);
                    Console.WriteLine(input + " is " + romanNummeral);

                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception was thrown " + ex.Message);
                    // log it do whatever...then continue
                }
            }
        }
    }
}